﻿<View:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="ExampleApp.Views.CommandsAndEventsView"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ExampleApp.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:View="using:StyleMVVM.View" xmlns:sys="using:System" View:ViewModel.Name="CommandsAndEventsViewModel"
    mc:Ignorable="d">

 <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="100"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Navigation.CanGoBack}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="Commands and Events" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>
        <TextBlock Grid.Row="1" Margin="20,5" FontSize="14" TextWrapping="Wrap">All applications handle events in one form or another.
            StyleMVVM provides two ways to subscribe for events in XAML, for controls that offer a Command property (such as button) you can use the DelegateCommand.
            If you need to handle other events like ItemClick or DoubleTapped then you should use the View:EventHandlers.Attach property to attach your model handlers.
        </TextBlock>
        
        <Button Content="Enable" Command="{Binding EnableCommand}" HorizontalAlignment="Left" Margin="56,57,0,0" Grid.Row="2" VerticalAlignment="Top"/>
        <Button Content="Disable" Command="{Binding DisableCommand}" HorizontalAlignment="Left" Margin="194,57,0,0" Grid.Row="2" VerticalAlignment="Top"/>
        <ListView View:EventHandlers.Attach="ItemClick => ItemClicked($sender,$eventArgs)" SelectionMode="None" IsItemClickEnabled="True"
            HorizontalAlignment="Left" Height="194" Margin="56,122,0,0" Grid.Row="2" VerticalAlignment="Top" Width="217" >
            <x:String>Hello</x:String>
            <x:String>GoodBye</x:String>
            <x:String>Hola</x:String>
            <x:String>Hasta la vista</x:String>
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</View:LayoutAwarePage>
